package de.hauschild.dbc4j.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import de.hauschild.dbc4j.ContractViolationException;
import de.hauschild.dbc4j.engine.ContractEngine;

/**
 * Each time a {@link PreCondition} annotated method is invoked the specified {@link #value() contract expression} will
 * be checked before invocation. This expression has to have the type {@link Boolean}. If the expressions result equals
 * <code>true</code> nothing will happen and the program continues. But if the expressions result equals
 * <code>false</code> a {@link ContractViolationException} will be thrown to indicate the violated contract.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
@Target( { ElementType.CONSTRUCTOR, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PreCondition {

  /**
   * Defines the {@link ContractEngine} to evaluate the defined precondition. Default is "groovy".
   */
  String engine() default "groovy";

  /**
   * Defines the precondition kept before the method is invoked. This expression has to have the type {@link Boolean} in
   * the context of the specified {@link ContractEngine}.
   */
  String value() default "";
}
